cd C:\Users\WSU\Desktop\data_analysis1

log using epds.log

use epds, clear

****giving label variables*****
label variable marr_n1 "marital status"
label variable age_cat "age"
label variable occ_n "occupation"
label variable gest_n3 "gestation age"
label variable edu_var2 "education level"
label variable par_n "parity"
label variable alc_drgn "alcohol and drug use"
label variable unpln_pgn2 "unplanned pregnancy"
label variable comp_n "pregnancy complications"
label variable ss_n2 "social support"
label variable dv_n2 "domestic violence"


recode epds (min/12=0) (13/max=1), gen (epds_n)
br epds epds_n

recode gest (min/12=1) (13/26=2) (17/max=3), gen (gest_n)
recode gest_n (1=0) (2=0) (3=1), gen (gest_n1)
recode gest_n1 (0=1)(1=0), gen (gest_n3)

recode dv_n (no=0) (yes=1)
recode dv_n (1=0) (2=1), gen (dv_n2) /* change dv_n to 0 or 1*/  
tab dv_n2, nolabel

recode ss_n (1=0) (2=1), gen (ss_n2) /* change ss_n to 0 or 1*/  
tab ss_n2, nolabel

xtile age_cat=age,nquantiles(3) /*divide data into quartiles*/
recode age (min/25=1) (26/29=2) (30/max=3), gen (age_cat)
tab age_cat
bysort age_cat: summ age /* determine age categories mn and max*/

recode educ_n (no formal education=primary) (secondary=secondary) (college=college), gen (educ_n1)
encode educ, gen(edu_var) /*encode education*/
recode edu_var (1=3) (2=1) (3=2), gen(edu_var2)
tab edu_var2

recode previs (0/1=1) (2=2) (3=3) (4/max=4), gen (previs_n)

recode mars_n (1=0) (2=1) (3=0), gen (marr)
recode marr (0=1)(1=0), gen (marr_n1)

recode pln_pgn1 (0=0)(2=1), gen (unpln_pgn1)
recode unpln_pgn1 (0=1) (1=0), gen (unpln_pgn2)

summ age, detail
summ previs, detail
summ gest, detail


tab epds_n age_cat, col chi
tab epds_n marr_n1, col chi
tab epds_n edu_var, col chi
tab epds_n occ_n, col chi
tab epds_n gest_n3, col chi
tab epds_n par_n, col chi
tab epds_n alc_drgn, col chi
tab epds_n unpln_pgn2, col chi
tab epds_n comp_n, col chi
tab epds_n ss_n, col chi
tab epds_n dv_n2, col chi

****univariable analysis*****
logistic marr_n1 epds_n
logistic epds_n i.age_cat
logistic epds_n ib2.edu_var2
logistic epds_n occ_n
logistic epds_n gest_n3
logistic epds_n par_n
logistic epds_n alc_drgn
logistic epds_n unpln_pgn2
logistic epds_n comp_n
logistic epds_n ss_n2
logistic epds_n dv_n2

****Multivariable analysis*****
xi: stepwise, pr(.05): logistic epds_n age_cat marr_n1 occ_n alc_drgn gest_n3 unpln_pgn2 dv_n2 ss_n

logistic epds_n i.age_cat marr_n1 occ_n alc_drgn gest_n3 unpln_pgn2 dv_n2 ss_n2 

logistic epds_n dv_n2 ss_n2 occ_n marr_n1   /* best model*/

estat gof, g(10) 

****assessing for interaction*****
logistic epds_n dv_n#ss_n dv_n ss_n occ_n marr_n1
logistic epds_n marr_n1#ss_n dv_n2 ss_n occ_n marr_n1
logistic epds_n marr_n1#dv_n dv_n2 ss_n occ_n marr_n1






